<template>
  <div id="appss">
  
    <router-view></router-view>

    <!-- 弹框 -->
    <el-dialog title="系统消息" :visible.sync="isShow" @close="closeFun">

      <el-form>

        <p style="padding: 20px 0px 10px;">管理员对您说：</p>
        <p style="text-indent: 45px;color: red;padding: 0px 0px 20px;">{{dataInfo.chat}}</p>

        <el-form-item label="">
          <el-input type="textarea" :rows="2" v-model="content"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sendFun">发 送</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>

  var timers = null;
  import axios from 'axios'
  export default {
    name: 'App',
    data(){
        return{
            
          isShow: false,
          dataInfo: {},
          content: '',
          settime: false,
          
        }
    },
    methods: {
        init(){

            var _this = this;

            if(window.localStorage.Authorization){
              
              if(_this.settime){
                clearInterval(timers);
                _this.isShow = false;
                return;
              }

              if (timers) {
                clearInterval(timers);
                timers = null;
              }

              _this.$httpGet('/api/other/nc').then(response => {
                          
                  if(response.status == 200){
                    _this.dataInfo = response.data;

                    if(response.data.chat){

                      _this.isShow = true;

                    }

                    timers = setInterval(() => {
                        _this.init();
                    }, 10 * 1000)
                      
                  }

              });

            }
            
        },
        sendFun(){
          
          var _this = this;

          _this.$httpPost('/api/other/addChat',{
            content: _this.content,
            to: _this.dataInfo.from,
          }).then(response => {
                    
                if(response.status == 200){
                  alert('发送成功');
                  _this.isShow = false;  
                }

            });

        },
        //关闭弹框
        closeFun(){
          
          this.settime = true;
        },
        
    },
    mounted(){
        this.init();
    },
  }


</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* text-align: center; */
  color: #2c3e50;
  /* margin-top: 60px; */
}
</style>
